﻿using System.Threading;
using System.Threading.Tasks;
using Iot.RealTimeData.RealTimeData;
using Iot.Shared.Enums;
using Iot.Shared.Model;
using Mediator;
using Microsoft.Extensions.Logging;

namespace Iot.RealTimeData.RealTimeDataEvent;

//todo  后面看着几个 能优化一下不 
public sealed class RealTimeDataEventSwitch(
    IRealTimeData<Switching?, IOnSwitchingValue> data,
    ILogger<RealTimeDataEventSwitch> logger)
    : INotificationHandler<SwitchBusModel>
{
    public ValueTask Handle(SwitchBusModel notification, CancellationToken cancellationToken)
    {
        logger.LogTrace("函数:{函数},开始处理通知{notification}.", nameof(Handle), notification);
        data.SetValue(notification.Path, notification.Value, notification.TimeStamp);
        logger.LogTrace("函数:{函数},通知{notification}设置值成功.", nameof(Handle), notification);
        return ValueTask.CompletedTask;
    }
}